//
//  SetBaseViewController.m
//  LocomotiveGuards
//
//  Created by zwj on 15-11-30.
//  Copyright (c) 2015年 REDOOR. All rights reserved.
//

#import "SetBaseViewController.h"

@interface SetBaseViewController ()
{
    UIView *_navbackview;
}
@end

@implementation SetBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _navbackview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20+44*H)];
    _navbackview.backgroundColor = [UIColor colorWithRed:(CGFloat)21/255 green:(CGFloat)124/255 blue:(CGFloat)244/255 alpha:1.0];
    [self.view addSubview:_navbackview];
}

- (UILabel *)createLabelFrame:(CGRect)frame title:(NSString *)title font:(UIFont *)font
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    if (title) {
        label.text = title;
    }
    if (font) {
        label.font = font;
    }
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 1;
    label.textColor = [UIColor whiteColor];
    return label;
}

- (UITextField *)createTextFieldFrame:(CGRect)frame title:(NSString *)title placeholder:(NSString *)placeholder
{
    UITextField *field = [[UITextField alloc] initWithFrame:frame];
    if (title) {
        field.text = title;
    }
    if (placeholder) {
        field.placeholder = placeholder;
    }
    field.borderStyle = UITextBorderStyleRoundedRect;
    field.textAlignment = NSTextAlignmentCenter;
    field.font = [UIFont systemFontOfSize:17];
    return field;
}

- (UIButton *)createBtnFrame:(CGRect)frame title:(NSString *)title bgImageName:(NSString *)bgImageName selectedImageName:(NSString *)selectedImageName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    if (title) {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    if (target && action) {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    if (bgImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateNormal];
    }
    if (selectedImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateHighlighted];
    }
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    return btn;
}

- (UIButton *)addBackBtnTarget:(id)target action:(SEL)action
{
    UIButton *btn = [self createBtnFrame:CGRectMake(15*W, 20+7*H, 30*H, 30*H) title:nil bgImageName:@"back01" selectedImageName:@"back01" target:target action:action];
    [_navbackview addSubview:btn];
    return btn;
}

- (UIButton *)addRightBtnTarget:(id)target action:(SEL)action
{
    UIButton *btn = [self createBtnFrame:CGRectMake(SCREEN_WIDTH-60*W, 20+8*H, 50*W, 30*H) title:@"编辑" bgImageName:nil selectedImageName:nil target:target action:action];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_navbackview addSubview:btn];
    return btn;
}

- (UIImageView *)addTitle:(NSString *)titleName imageName:(NSString *)imageName
{
    UIImageView *titleImgView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-(15+5+70)*W)/2, 20+16*H, 15*H, 15*H)];
    titleImgView.image = [UIImage imageNamed:imageName];
    [_navbackview addSubview:titleImgView];
    
    UILabel *titleLabel = [self createLabelFrame:CGRectMake((SCREEN_WIDTH-(15+5+70)*W)/2+20*W, 20+8*H, 80*W, 30*H) title:titleName font:[UIFont systemFontOfSize:18/W]];
    [_navbackview addSubview:titleLabel];
    return titleImgView;
}

-(void)viewWillAppear:(BOOL)animated{
    NSDictionary *dic = @{@"key":@"3"};
    [[NSNotificationCenter defaultCenter]postNotificationName:@"changetabbartwo" object:nil userInfo:dic];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
